import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Wolve here.
 * 
 * @author (Gerardo Antonio Hernandez Garcia & Christian Israel Rodriguez Ahumada ) 
 * @version (a version number or a date)
 */
public class Wolve extends Enemigo
{

    private GreenfootImage imagenDer[]= new GreenfootImage [6];
    private GreenfootImage imagenIzq[]= new GreenfootImage [6];
    private GreenfootImage ataIzq[]= new GreenfootImage [3];
    private GreenfootImage ataDer[]= new GreenfootImage [3];
    private int dir;
    private int numIma;
    private int cont;
    private int numEsp;
    private int golpes;
    private static final int maxEsp=5;

    /**
     * CONSTRUCTOR DE WOLVE
     */
    public Wolve()
    {
        dir=1;
        numIma=0;
        cont=0;
        this.CargarArregloIma();
        numEsp=0;
        golpes=1;
    }

    /**
     * Act - do whatever the Wolve wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        World mundo= getWorld();
        numEsp= (numEsp+1)%maxEsp;
        if(numEsp!=0)
            return;
        this.mueve();

        if(isTouching(Heroe.class))
        {
            Actor a=getOneIntersectingObject(Heroe.class);
            if(dir==1)
                for(int i=0;i<3;i++)
                {
                    numIma = (numIma + 1) % 3;
                    setImage( ataDer[numIma] );
                    Greenfoot.delay(4);
            }
            else
                for(int i=0;i<3;i++)
                {
                    numIma = (numIma + 1) % 3;
                    setImage( ataIzq[numIma] );
                    Greenfoot.delay(4);
            }
             ((Heroe)a).decrementaVidas();
            ((Heroe)a).goHome();
        }

        if(isTouching(Bala.class))
        {
            Actor a=getOneIntersectingObject(Bala.class);
            if(golpes==2)
            {
            //Actor a=getOneIntersectingObject(Bala.class);
          
            Greenfoot.playSound("muere.wav");
            setImage("nitro1.png");
            Greenfoot.delay(5);
            mundo.removeObject(this);
            mundo.removeObject(a);
            }
            
            mundo.removeObject(a);
            golpes++;
        }

    }    
    /**
     * ARREGLO DE IMAGENES
     */
    public void CargarArregloIma()
    {
        for(int i=0; i<6; i++)
        {
            imagenDer[i]= (new GreenfootImage("Der"+(i)+".png"));
            imagenIzq[i]= (new GreenfootImage("Izq"+(i)+".png"));
        }
        for(int i=0; i<3; i++)
        {
            ataDer[i]= (new GreenfootImage("AtaDer"+(i)+".png"));
            ataIzq[i]= (new GreenfootImage("AtaIzq"+(i)+".png"));
        }
    }

    /**
     * MUEVE AL ENEMIGO 
     */
    public void mueve()
    {
        World mundo= getWorld();
        GreenfootImage ima= getImage();
        if((dir==1 && cont<=50))
        {
            numIma = (numIma + 1) % 6;
            setImage( imagenDer[numIma] );
            move(5);

            cont++;
            if((this.getX()+(ima.getWidth()/2))>690)
            {
                cont=51;

            }

        }

        if (cont==51)
            dir=2;

        if((dir==2 && cont>50 && cont<=101))
        {
            numIma = (numIma + 1) % 6;
            setImage( imagenIzq[numIma] );
            move(-5);

            cont++;

            if ((this.getX()-(ima.getWidth()/2)<3))
            {
                cont=102;

            }
        }

        if(cont==102)
        {

            cont=0;
            dir=1;
        }

        
        
    }
}
